package com.pxxy.yuyi.controller;

import com.github.pagehelper.PageInfo;
import com.pxxy.yuyi.entity.Admin;
import com.pxxy.yuyi.entity.Order;
import com.pxxy.yuyi.service.OrderService;
import com.pxxy.yuyi.utils.ConstUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by IntelliJ IDEA
 *
 * @Author : XuWen
 * @create 2021/6/20 15:51
 */
@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    //前台提交预约信息
    @RequestMapping("/add")
    public String add(Order order, HttpServletRequest request){
       Integer res= orderService.insertOrder(order);
       if(res==null){
        request.setAttribute("mes","预约失败，请从新预约!");
        return "faqReserve";
       }
       request.setAttribute("mes","预约成功,后续我们将为您安排并与您联系,感谢您支持语翼教育,更多详情请关注微信公共号。");
        return "forward:/teachers/show";
    }
    //后台展示预约信息
    @RequestMapping("/show")
    public String show(HttpServletRequest request,Integer pageNum,String oname){
        //1.先要判断是否有登录，没有登录，则先进行登录
        if (pageNum==null){
            pageNum=1;
        }
        Admin admin = (Admin) request.getSession().getAttribute(ConstUtils.LOGIN_USER);
        if (admin==null) {//为空则先进行登录
            request.setAttribute("msg", "请先登录");
            return "admin/adminLogin";
        }else{
            PageInfo<Order> info = orderService.showOrder(pageNum,oname);
            request.setAttribute("pi",info);
            return "admin/order";
        }
    }
    //后台删除预约信息
    @RequestMapping("/deleteOrder")
    public String deleteOrder(Integer oid){
        Integer result = orderService.deleteOrder(oid);
        return "forward:/order/show";
    }

}
